<?php



//  Definition for a singly-linked list.
class ListNode {
     public $val = 0;
     public $next = null;
     function __construct($val) { $this->val = $val; }
}

class Solution {

    /**
     * @param ListNode $head
     * @param Integer $x
     * @return ListNode
     */
    function partition($head, $x) {
        if($head->next==null){
            return $head;
        }
        $smallStatic=null;
        $bigStatic=null;
        $small=null;
        $big=null;
        while(true){
            if($head!=null)
            {
                if ($head->val < $x) {
                    $temp = new ListNode($head->val);
                    if ($smallStatic == null) {
                        $smallStatic = $temp;
                        $small = $smallStatic;
                    } else {
                        $small->next = $temp;
                        $small = $small->next;
                    }
                } else {
                    $temp = new ListNode($head->val);
                    if ($bigStatic == null) {
                        $bigStatic = $temp;
                        $big = $bigStatic;
                    } else {
                        $big->next = $temp;
                        $big = $big->next;
                    }
                };
                $head = $head->next;
            }
            else{
                break;
            }


        }
        if($small!=null) {
            $small->next = $bigStatic;
            return $smallStatic;
        }else{
            return $bigStatic;
        }
    }
}




?>